﻿using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using WorkFlowBLL;
using System.Collections.Generic;

namespace QLCF.Forms
{
    public partial class frmStockDetail : Form
    {
        public frmStock m_parrent;
        public Boolean isAddData = false;
        public int m_stockID = -1;
        public int m_productID = -1;
        private string m_productIds = string.Empty;
        private List<string> lstString = new List<string>();
        public frmStockDetail(frmStock Parent)
        {            
            InitializeComponent();
            this.m_parrent = Parent;
            this.isAddData = Parent.isAddData;
            this.m_stockID = Parent.m_stockID;
            if (!this.isAddData)
            {
                int? totalMoney = 0;
                CtrBase ctrBase = new CtrBase();
                var lstItem = ctrBase.StockDetailGetList(this.m_stockID, ref totalMoney);
                int currentPrice = 0;                                
                foreach (var item in lstItem)
                {
                    ListViewItem item1 = new ListViewItem(item.ProductName);
                    item1.SubItems.Add(item.Unit);
                    item1.SubItems.Add(item.Quantity.ToString());
                    item1.SubItems.Add(item.Price.ToString());
                    item1.SubItems.Add(item.TotalMoney);
                    item1.Tag = item.ProductID;
                    this.m_productID = item.ProductID;
                    currentPrice += Convert.ToInt32(item.Price * item.Quantity);
                    listViewStockDetail.Items.Add(item1);                    
                }
                numericTotalMoney.Value = currentPrice;
            }
        }

        public void Load_StockDetail()
        {
            CtrBase ctrBase = new CtrBase();
            int? totalMoney = 0;
            var lstItemStock = ctrBase.StockDetailGetList(this.m_stockID, ref totalMoney);
            foreach (var item in lstItemStock)
            {
                ListViewItem item1 = new ListViewItem();
                item1.SubItems.Add(item.ProductName); 
            }
        }

        private void frmStockDetail_Load(object sender, EventArgs e)
        {
            loadCate();
            loadDistribute();
            treeViewCategory.SelectedNode = treeViewCategory.Nodes[0];            
            dateTimePicker1.Focus();
            listViewProduct.Columns[listViewProduct.Columns.Count - 1].Width = -2;
            listViewStockDetail.Columns[listViewStockDetail.Columns.Count - 1].Width = -2;
            numQuantity.DecimalPlaces = 2;
            numQuantity.Increment = 0.1M;

            CheckPermisson();
        }

        private void loadCate()
        {
            TreeNode node1 = new TreeNode();
            node1.Text = "Tất cả";
            node1.Tag = -1;
            node1.ImageIndex = 1;
            node1.SelectedImageIndex = 1;
            treeViewCategory.Nodes.Add(node1);
            CtrCategory ctrC = new CtrCategory();
            var items = ctrC.GetListCategory();
            foreach (var item in items)
            {
                TreeNode node = new TreeNode();
                node.Text = item.CategoryName;
                node.Tag = item.CategoryID;
                node.ImageIndex = 0;
                treeViewCategory.Nodes.Add(node);
            }
        }

        private void loadDistribute()
        {

            CtrBase ctrBase = new CtrBase();
            var objBase = ctrBase.GetListDistribution();
            cbxDistribute.DataSource = objBase;
            cbxDistribute.DisplayMember = "DistributeName";
            cbxDistribute.ValueMember = "DistributeID";           
        }

        private bool Resizing = false;

        private void listViewProduct_SizeChanged(object sender, EventArgs e)
        {
            // Don't allow overlapping of SizeChanged calls
            if (!Resizing)
            {
                // Set the resizing flag
                Resizing = true;

                ListView listView = sender as ListView;
                if (listView != null)
                {
                    float totalColumnWidth = 0;

                    // Get the sum of all column tags
                    for (int i = 0; i < listView.Columns.Count; i++)
                        totalColumnWidth += Convert.ToInt32(listView.Columns[i].Tag);

                    // Calculate the percentage of space each column should 
                    // occupy in reference to the other columns and then set the 
                    // width of the column to that percentage of the visible space.
                    for (int i = 0; i < listView.Columns.Count; i++)
                    {
                        float colPercentage = (Convert.ToInt32(listView.Columns[i].Tag) / totalColumnWidth);
                        listView.Columns[i].Width = (int)(colPercentage * listView.ClientRectangle.Width);
                    }
                }
            }

            // Clear the resizing flag
            Resizing = false;
        }

        private void listViewStockDetail_SizeChanged(object sender, EventArgs e)
        {
            // Don't allow overlapping of SizeChanged calls
            if (!Resizing)
            {
                // Set the resizing flag
                Resizing = true;

                ListView listView = sender as ListView;
                if (listView != null)
                {
                    float totalColumnWidth = 0;

                    // Get the sum of all column tags
                    for (int i = 0; i < listView.Columns.Count; i++)
                        totalColumnWidth += Convert.ToInt32(listView.Columns[i].Tag);

                    // Calculate the percentage of space each column should 
                    // occupy in reference to the other columns and then set the 
                    // width of the column to that percentage of the visible space.
                    for (int i = 0; i < listView.Columns.Count; i++)
                    {
                        float colPercentage = (Convert.ToInt32(listView.Columns[i].Tag) / totalColumnWidth);
                        listView.Columns[i].Width = (int)(colPercentage * listView.ClientRectangle.Width);
                    }
                }
            }

            // Clear the resizing flag
            Resizing = false;
        }

        private void tsbClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void treeViewCategory_AfterSelect(object sender, TreeViewEventArgs e)
        {            
            listViewProduct.Items.Clear();
            var cateID = Convert.ToInt32(e.Node.Tag);
            CtrProduct ctrT = new CtrProduct();
            var items = ctrT.ProductGetByCate("", cateID, 0, 1, 1);
            foreach (var item in items)
            {
                ListViewItem item1 = new ListViewItem(item.ProductName);
                item1.SubItems.Add(item.Unit);
                item1.SubItems.Add(item.PriceName);
                item1.Tag = item.ProductID;
                listViewProduct.Items.Add(item1);
            }
            e.Node.BackColor = Color.FromArgb(220, 220, 220);        
        }

        private void treeViewCategory_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            if (treeViewCategory.SelectedNode != null)
                treeViewCategory.SelectedNode.BackColor = Color.Transparent;
        }

        private void txtKeyword_KeyDown(object sender, KeyEventArgs e)
        {
            listViewProduct.Items.Clear();
            var cateID = Convert.ToInt32(treeViewCategory.SelectedNode.Tag);
            CtrProduct ctrT = new CtrProduct();
            var items = ctrT.ProductGetByCate(txtKeyword.Text, cateID, 0, -1, -1);
            foreach (var item in items)
            {
                ListViewItem item1 = new ListViewItem(item.ProductName);
                item1.SubItems.Add(item.Unit);
                item1.SubItems.Add(item.PriceName);
                item1.Tag = item.ProductID;
                listViewProduct.Items.Add(item1);
            }
        }                       

        private void listViewProduct_DoubleClick(object sender, EventArgs e)
        {
            if (listViewProduct.SelectedItems.Count <= 0) return;
            if (listViewProduct.SelectedItems.Count > 0) listViewProduct.SelectedItems[0].BackColor = Color.FromArgb(220, 220, 220);
            var itemIDClick = listViewProduct.SelectedItems[0];                        

            bool isCurrent = false;
            foreach (ListViewItem itemN in listViewStockDetail.Items)
            {
                if (Convert.ToInt32(itemIDClick.Tag) == Convert.ToInt32(itemN.Tag))
                {
                    isCurrent = true;
                    float curQuantity = (float)Convert.ToDouble(itemN.SubItems[2].Text);
                    itemN.SubItems[2].Text = ((float)(curQuantity + (float)(numQuantity.Value))).ToString();
                    itemN.SubItems[4].Text = Convert.ToInt32(Convert.ToInt32(itemN.SubItems[3].Text) * Convert.ToDouble(itemN.SubItems[2].Text)).ToString();                                       
                }                
            }
                        
            if (!isCurrent)
            {
                var lstItem = new ListViewItem(itemIDClick.Text);
                lstItem.Tag = itemIDClick.Tag;
                itemIDClick.BackColor = Color.FromArgb(220, 220, 220);
                lstItem.SubItems.Add(itemIDClick.SubItems[1].Text);
                lstItem.SubItems.Add(numQuantity.Value.ToString());
                lstItem.SubItems.Add(numericPrice.Value.ToString());
                lstItem.SubItems.Add(Convert.ToInt32(numQuantity.Value * numericPrice.Value).ToString());                
                listViewStockDetail.Items.Add(lstItem);                
            }

            float currentPrice = 0;
            foreach (ListViewItem itemN in listViewStockDetail.Items)
            {
                currentPrice += (float)Convert.ToDecimal(itemN.SubItems[4].Text);                
            }
            numericTotalMoney.Value = Convert.ToDecimal(currentPrice);

            CheckPermisson();
        }

        private void listViewProduct_SelectedIndexChanged(object sender, EventArgs e)
        {            
            foreach (ListViewItem pro in listViewProduct.Items)
            {
                if (pro.BackColor != Color.Transparent)
                    pro.BackColor = Color.Transparent;                
            }
            if (listViewProduct.SelectedItems.Count > 0)
                listViewProduct.SelectedItems[0].BackColor = Color.FromArgb(220, 220, 220);
            if (listViewProduct.SelectedItems.Count <= 0) return;            
            var itemIDClick = listViewProduct.SelectedItems[0];
            int ProductID = Convert.ToInt32(itemIDClick.Tag);
            CtrProduct ctrp = new CtrProduct();
            int unitID = ctrp.ProductGetInfo(ProductID).UnitID;
            CtrBase ctrb = new CtrBase();
            var info=ctrb.UnitGetInfo(unitID);
            var items = ctrb.GetUnitByBaseUnitID(unitID);
            var m_unitInfo = new DataContext.uspUnitGetByBaseUnitIDResult();
            m_unitInfo.UnitID = info.UnitID;
            m_unitInfo.MultiPhy = 1;
            m_unitInfo.Name = info.Name;
            items.Insert(0, m_unitInfo);
            cbxUnit.DisplayMember = "Name";
            cbxUnit.ValueMember = "MultiPhy";
            cbxUnit.DataSource = items;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (listViewProduct.SelectedItems.Count <= 0) return;
            if (listViewProduct.SelectedItems.Count > 0) listViewProduct.SelectedItems[0].BackColor = Color.FromArgb(220, 220, 220);
            var itemIDClick = listViewProduct.SelectedItems[0];

            bool isCurrent = false;
            foreach (ListViewItem itemN in listViewStockDetail.Items)
            {
                if (Convert.ToInt32(itemIDClick.Tag) == Convert.ToInt32(itemN.Tag))
                {
                    isCurrent = true;
                    float curQuantity = (float)Convert.ToDouble(itemN.SubItems[2].Text);
                    itemN.SubItems[2].Text = ((float)(curQuantity + (float)(numQuantity.Value * (int)cbxUnit.SelectedValue))).ToString();
                    itemN.SubItems[4].Text = Convert.ToInt32((Convert.ToInt32(itemN.SubItems[3].Text) * Convert.ToDouble(itemN.SubItems[2].Text))).ToString();                    
                }
            }

            if (!isCurrent)
            {
                var lstItem = new ListViewItem(itemIDClick.Text);
                lstItem.Tag = itemIDClick.Tag;
                itemIDClick.BackColor = Color.FromArgb(220, 220, 220);
                lstItem.SubItems.Add(itemIDClick.SubItems[1].Text);
                lstItem.SubItems.Add((numQuantity.Value *(int)cbxUnit.SelectedValue).ToString());
                lstItem.SubItems.Add(numericPrice.Value.ToString());
                lstItem.SubItems.Add(Convert.ToInt32(numQuantity.Value * (int)cbxUnit.SelectedValue * numericPrice.Value).ToString());
                listViewStockDetail.Items.Add(lstItem);
            }

            float currentPrice = 0;
            foreach (ListViewItem itemN in listViewStockDetail.Items)
            {
                currentPrice += (float)Convert.ToDecimal(itemN.SubItems[4].Text);
            }
            numericTotalMoney.Value = Convert.ToDecimal(currentPrice);

            CheckPermisson();
        }

        private void btnSub_Click(object sender, EventArgs e)
        {
            ListViewItem[] selectedItems = (from ListViewItem i in listViewStockDetail.Items where i.Selected select i).ToArray();            
            if (selectedItems.Count() > 0)
            {
                foreach (ListViewItem item in selectedItems)
                {
                    item.BackColor = Color.FromArgb(220, 220, 220);
                    float curQuantity = (float)Convert.ToDouble(item.SubItems[2].Text);
                    if (curQuantity > 1 && curQuantity > (float)(numQuantity.Value))
                    {
                        item.SubItems[2].Text = ((float)(curQuantity - (float)(numQuantity.Value))).ToString();                        
                        item.SubItems[4].Text = (Convert.ToInt32(item.SubItems[3].Text) * (float)Convert.ToDouble(item.SubItems[2].Text)).ToString();                        
                    }
                    else
                    {
                        MessageBox.Show("Số lượng ít nhất là 1", "Thông báo");
                        return;
                    }
                }
                float currentPrice = 0;                        
                foreach (ListViewItem itemN in listViewStockDetail.Items)
                {
                    currentPrice += (float)Convert.ToDecimal(itemN.SubItems[4].Text);
                }
                numericTotalMoney.Value = Convert.ToDecimal(currentPrice);

                CheckPermisson();
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn mặt hàng cần giảm số lượng", "Thông báo");
                return;
            }        
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            ListViewItem[] selectedItems = (from ListViewItem i in listViewStockDetail.Items where i.Selected select i).ToArray();
            if (selectedItems.Count() > 0)
            {                    
                foreach (ListViewItem item in selectedItems) { 
                    listViewStockDetail.Items.Remove(item);
                    lstString.Add(item.Tag.ToString());                    
                }                
                float currentPrice = 0;
                foreach (ListViewItem itemN in listViewStockDetail.Items)
                {
                    currentPrice += (float)Convert.ToDecimal(itemN.SubItems[4].Text);
                }
                numericTotalMoney.Value = Convert.ToDecimal(currentPrice);
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn mặt hàng cần xóa", "Thông báo");
                return;
            }
            CheckPermisson();            
        }

        private void tsbAdd_Click(object sender, EventArgs e)
        {
            if (listViewStockDetail.Items.Count > 0)
            {
                if (this.isAddData)
                {
                    CtrBase ctrBase = new CtrBase();
                    var objInsert = ctrBase.StockInsert((int)Convert.ToInt32(numericTotalMoney.Value), Convert.ToInt32(cbxDistribute.SelectedValue), txtDesciption.Text, dateTimePicker1.Value, Program.UserEntity.m_userID, 1);
                                        
                    if (objInsert > 0)
                    {
                        CtrAdmin ctra = new CtrAdmin();
                        //ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 1, "Thêm mới kho có mã \"" + objInsert + "\"", "Quản lý kho hàng");                        
                        foreach (ListViewItem listItem in listViewStockDetail.Items)
                        {
                            var objInsertResult = ctrBase.StockDetailInsert(objInsert, Convert.ToInt32(listItem.Tag), listItem.SubItems[0].Text, Convert.ToDouble(listItem.SubItems[2].Text), (int)Convert.ToInt32(listItem.SubItems[3].Text), dateTimePicker1.Value);
                            if (objInsertResult > 0)
                            {
                                ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 1, "Thêm mới vào kho sản phẩm \"" + listItem.SubItems[0].Text + "\" với số lượng " + "\"" + listItem.SubItems[2].Text + "\" giá " + "\"" + listItem.SubItems[3].Text + "\"", "Quản lý kho hàng");
                            }
                        }                        
                        m_parrent.BindStock();
                        this.Close();
                    }
                }
                else
                {
                    CtrBase ctrBase = new CtrBase();
                    var m_strInsertStockIds = string.Empty;
                    var m_strUpdateStockIds = string.Empty;
                    if(lstString.Count > 0)
                    {
                        foreach (var item in lstString)
                        {
                            var index = ctrBase.CheckExistStockDetail(this.m_stockID, Convert.ToInt32(item));
                            if (index > 0)
                            {
                                var objDelete1 = ctrBase.StockDetailDelete(this.m_stockID, Convert.ToInt32(item));
                                if (objDelete1 > 0)
                                {
                                    CtrAdmin ctra = new CtrAdmin();
                                    ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 3, "Xóa mặt hàng trong kho hàng có mã \"" + objDelete1 + "\"", "Quản lý nhập kho");
                                }
                            }
                        }                        
                    }
                    var objUpdate = ctrBase.StockUpdate(this.m_stockID, (int)Convert.ToInt32(numericTotalMoney.Value), Convert.ToInt32(cbxDistribute.SelectedValue), txtDesciption.Text, dateTimePicker1.Value, Program.UserEntity.m_userID, 1);
                    if (objUpdate > 0)
                    {
                        CtrAdmin ctra = new CtrAdmin();
                        //ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 2, "Cập nhật kho hàng có mã \"" + this.m_stockID + "\"", "Quản lý kho hàng");

                        foreach (ListViewItem listItem in listViewStockDetail.Items)
                        {
                            var objStockDetail = ctrBase.CheckExistStockDetail(this.m_stockID, Convert.ToInt32(listItem.Tag));
                            if (objStockDetail == 0)
                            {
                                var objInserRetsult1 = ctrBase.StockDetailInsert(this.m_stockID, Convert.ToInt32(listItem.Tag), listItem.SubItems[0].Text, Convert.ToDouble(listItem.SubItems[2].Text), (int)Convert.ToInt32(listItem.SubItems[3].Text), dateTimePicker1.Value);
                                if (objInserRetsult1 > 0)
                                {
                                    ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 1, "Thêm mới vào kho sản phẩm\"" + listItem.SubItems[0].Text + "\" với só lượng " + "\"" + listItem.SubItems[2].Text + "\" với giá " + "\"" + listItem.SubItems[3].Text + "\"", "Quản lý kho hàng");
                                }
                            }
                            else
                            {
                                var objStock = ctrBase.GetStockDetail(objStockDetail);
                                var objUpdateResult1 = ctrBase.StockDetailUpdate(objStockDetail, Convert.ToInt32(listItem.Tag), Convert.ToDouble(listItem.SubItems[2].Text), (int)Convert.ToInt32(listItem.SubItems[3].Text), dateTimePicker1.Value);
                                if (objUpdateResult1 > 0)
                                {
                                    
                                    if (Convert.ToInt32(listItem.SubItems[3].Text) != objStock.Price)
                                    {
                                        ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 2, "Thay đổi giá bán sản phẩm trong kho sản phẩm \"" + listItem.SubItems[0].Text + "\" thành" + "\"" + listItem.SubItems[3].Text + "\"", "Quản lý kho hàng");
                                    }
                                    if (Convert.ToDouble(listItem.SubItems[2].Text) != objStock.Quantity)
                                    {
                                        ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 2, "Thay đổi số lượng sản phẩm trong kho sản phẩm \"" + listItem.SubItems[0].Text + "\" thành" + "\"" + listItem.SubItems[2].Text + "\"", "Quản lý kho hàng");
                                    }
                                }
                            }
                        }
                        m_parrent.BindStock();
                        this.Close();
                    }
                }
            }
            else
            {
                if (this.m_stockID != -1)
                {
                    if (MessageBox.Show("Bạn có muốn xóa hóa đơn nhập hàng này không ?", "Thông báo...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
                    CtrBase ctrBase = new CtrBase();
                    var objDelete = ctrBase.StockDelete(this.m_stockID);
                    if(objDelete>0)
                    {
                        CtrAdmin ctra = new CtrAdmin();
                        ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 3, "Xóa mặt hàng trong kho hàng có mã \"" + this.m_stockID + "\"", "Quản lý nhập kho");
                        m_parrent.BindStock();
                        m_parrent.BindStockDetail();
                        this.Close();
                    }                    
                }
                else
                {
                    MessageBox.Show("Bạn chưa nhập sản phẩm nào !", "Thông báo...");
                    return;
                }
            }
        }

        private void CheckPermisson()
        {
            if (listViewStockDetail.Items.Count > 0)
            {
                //btnSub.Enabled = true;
                btnDelete.Enabled = true;
                //tsbAdd.Enabled = true;
            }
            else
            {
                //btnSub.Enabled = false;
                btnDelete.Enabled = false;
                //tsbAdd.Enabled = false;
            }
        }

        private void toolStripMenuItemDelete_Click(object sender, EventArgs e)
        {
            CtrBase ctrBase = new CtrBase();
            if (listViewStockDetail.SelectedItems.Count <= 0)
            {
                MessageBox.Show("Bạn chưa chọn bản ghi cần xóa", "Thông báo");
                return;                
            }
            var item = listViewStockDetail.SelectedItems[0];
            var objReturn = ctrBase.StockDetailDelete(this.m_stockID, Convert.ToInt32(item.Tag));
            if (objReturn > 0)
            {
                MessageBox.Show("Xóa bản ghi thành công", "Thông báo");                
                btnDelete.PerformClick();
                m_parrent.BindStock();
                return;  
            }
        }        

        private void toolStripMenuItemEditPrice_Click(object sender, EventArgs e)
        {
            if (listViewStockDetail.SelectedItems.Count <=0)
                return;
            var item = listViewStockDetail.SelectedItems[0];
            popupStockSetPrice popPrice = new popupStockSetPrice(this, Convert.ToInt32(item.Tag), item.SubItems[0].Text, Convert.ToInt32(item.SubItems[3].Text));
            popPrice.ShowDialog();
        }

        private void toolStripMenuItemUpdateNumber_Click(object sender, EventArgs e)
        {
            if (listViewStockDetail.SelectedItems.Count <= 0)
                return;
            var item = listViewStockDetail.SelectedItems[0];
            popupStockSetQuantity popPrice = new popupStockSetQuantity(this, Convert.ToInt32(item.Tag), item.SubItems[0].Text, item.SubItems[1].Text, Convert.ToDouble(item.SubItems[2].Text));
            popPrice.ShowDialog();
        }
 
        private void contextMenuStripOnProduct_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (listViewStockDetail.SelectedItems.Count != 1)
            {                                
                toolStripMenuItemEditPrice.Enabled = false;
                toolStripMenuItemUpdateNumber.Enabled = false;
            }
            else
            {                
                toolStripMenuItemEditPrice.Enabled = true;
                toolStripMenuItemUpdateNumber.Enabled = true;
            }            
        }

        public void updateQuantity(int stockDetailID, float quantity)
        {
            float currentPrice = 0;
            foreach (ListViewItem itemN in listViewStockDetail.Items)
            {
                if (stockDetailID == Convert.ToInt32(itemN.Tag))
                {
                    itemN.SubItems[2].Text = quantity.ToString();
                    itemN.SubItems[4].Text = Convert.ToInt32((Convert.ToInt32(itemN.SubItems[3].Text) * Convert.ToDouble(itemN.SubItems[2].Text))).ToString();                    
                }
                currentPrice += (float)Convert.ToDecimal(itemN.SubItems[4].Text);
            }
            numericTotalMoney.Value = Convert.ToDecimal(currentPrice);
        }

        public void updatePrice(int stockDetailID, int price)
        {
            float currentPrice = 0;
            foreach (ListViewItem itemN in listViewStockDetail.Items)
            {
                if (stockDetailID == Convert.ToInt32(itemN.Tag))
                {
                    itemN.SubItems[3].Text = price.ToString();
                    itemN.SubItems[4].Text = Convert.ToInt32((Convert.ToInt32(itemN.SubItems[3].Text) * Convert.ToDouble(itemN.SubItems[2].Text))).ToString();                    
                }
                currentPrice += (float)Convert.ToDecimal(itemN.SubItems[4].Text);
            }
            numericTotalMoney.Value = Convert.ToDecimal(currentPrice);
        }

        private void listViewProduct_Click(object sender, EventArgs e)
        {
            var itemIDClick = listViewProduct.SelectedItems[0];
            foreach (ListViewItem pro in listViewProduct.Items)
            {               
                if (Convert.ToInt32(itemIDClick.Tag) == Convert.ToInt32(pro.Tag))
                {
                    numericPrice.Value = Convert.ToDecimal(pro.SubItems[2].Text);
                }
            }
        }
    }
}